<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>    
<%@ page import="java.util.*" %>
<%@ page import="org.swim.entity.Ability" %>
<%@ page import="org.swim.entity.User" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Search By Ability</title>
	<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
	<%@ include file="NavBar.jsp" %>
	<div class="container">
	<h1>Search By Ability</h1>
	<%	boolean areThereAbilities = (Boolean) request.getAttribute("areThereAbilities"); 
		if(areThereAbilities) {
			List<Ability> abilities = (List<Ability>) request.getAttribute("abilities"); 
			if(!(abilities.size()==0)) { %> 
				<div class="row">
					<form action="SearchByAbility" method="post" class="navbar-search pull-left">
					<p>Choose an ability</p>
					<% for (Ability current: abilities) {  %>
						<div class="row">
							<label class="radio">
								<input type="radio" name="ability" value="<% out.print(current.getIdAbilita()); %>"><% out.print(current.getNome()); %>
							</label>	
						</div>
					<% } %>
					<p>Choose your search domain</p>
					<div class="row">
						<label class="radio">
							<input type="radio" name="domain" value="all" checked>Search in all users
						</label>	
					<% if (!session.getAttribute("status").equals("guest")) { %>
							<label class="radio">
								<input type="radio" name="domain" value="friends">Search only in your friends
							</label>	
					<% } %>
					</div>
			<% } else { %>
				<div class="alert alert-info"><strong>No abilities:</strong> there are no abilities you can search</div>
			<% } %>
				<button type="submit" class="btn">Search</button>
			</form>
		</div>
		<% } else { %>
			<div class="alert alert-info"><strong>No abilities:</strong> there are no abilities you can search</div>	
		<% } %>
		<% 
		try {
			ArrayList<User> results = (ArrayList<User>) request.getAttribute("searchResults");	%>
			<div class="container">
			<h2>Search Results</h2>		
			<%	for(User u:results) {%>
				<div class="row">
					<div class="media"><a class="pull-left" href="<% out.print("Profile?id="+ u.getId());%>">
					<img class="media-object" alt="64x64" style="width: 64px; height: 64px;" src="<% out.print(u.getAvatar()); %>" data-src="holder.js/64x64">
					<div class="media-body">		
				    <h4 class="media-heading"><% out.print(u.getNome() + " " + u.getCognome()); %></h4></div></a></div>
			    </div>
			<% } %>
				</div>
			<%	} catch (NullPointerException e) {
				
			} %> 
	</div>
</body>
</html>